#include<iostream>
#include<unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

using namespace std;

int main(int argc,char*argv[]){
	
	int ret = 0;
	int fd = 0;
	char *filename;
	char read_buf[100],write_buf[100]="hello,driver1";
	
	if(argc < 2){
		cout << "cmd one param!" << endl;
		return -5;
	}
	
	filename = argv[1];
	
	fd = open(filename,O_RDWR);
	if(fd < 0){
		cout << "Cannot open file,"<<filename<< endl;
		return -1;
	}
	
	ret = read(fd,read_buf,100);
	if(ret < 0){
		cout << "read file "<<filename << " failed."<<endl;
		return -2;
	}
	cout<< "read buf:" << read_buf << endl;
	
	ret = write(fd,write_buf,100);
	
	if(ret <0){
		cout << "write file "<< filename << " failed." <<endl;
		return -3;
	}
	
	ret = close(fd);
	
	if(ret <0){
		cout << "close file "<< filename << " failed." <<endl;
		return -3;
	}
	
	cout << "app end" << endl;

	return 0;
}
